package com.ctsi.framework.mybatis.dialect;

import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: zhangjw
 * @Date: 2018/7/4 10:10
 * @Description:
 */
@Configuration
@AutoConfigureBefore(MybatisAutoConfiguration.class)
public class DialectConfiguration {


    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "mysql",matchIfMissing = false)
    public Dialect mysqlDialect(){
        return new MySQLDialect();
    }

    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "db2",matchIfMissing = false)
    public Dialect db2Dialect(){
        return new DB2Dialect();
    }

    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "fb2",matchIfMissing = false)
    public Dialect fb2Dialect(){
        return new Fb2Dialect();
    }

    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "fb",matchIfMissing = false)
    public Dialect fbDialect(){
        return new FbDialect();
    }

    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "gbase",matchIfMissing = false)
    public Dialect gbaseDialect(){
        return new GbaseDialect();
    }

    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "h2",matchIfMissing = false)
    public Dialect h2Dialect(){
        return new H2Dialect();
    }

    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "ms05",matchIfMissing = false)
    public Dialect ms05Dialect(){
        return new Ms05Dialect();
    }

    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "ms",matchIfMissing = false)
    public Dialect msDialect(){
        return new MsSqlDialect();
    }

    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "oracle",matchIfMissing = false)
    public Dialect oracleDialect(){
        return new OraDialect();
    }

    @Bean
    @ConditionalOnProperty(value = "spring.datasource.platform",havingValue = "pos",matchIfMissing = false)
    public Dialect posDialect(){
        return new PosDialect();
    }
}
